<template>
	<view class="page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<pageTxt>
			<z-paging ref="paging" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<view class="navbar-box">
						<u-navbar title="勘场资料" :autoBack="true" :fixed="false"></u-navbar>
					</view>
				</template>
				<view class="add-content ios">
					<u--form labelPosition="top" :model="formData" ref="uForm" labelWidth="auto">
						<view class="form-box">
							<u-form-item labelPosition="top" labelWidth="100%" required label="资料文件(.zip,.ppt,.xls,.pdf,.doc,.docx,.xlsx,rar)" borderBottom>
								<file-upload
									:filesList="list"
									:type="4"
									:typeList="['zip', 'ppt', 'xls', 'pdf', 'doc', 'docx', 'xlsx', 'rar']"
									@afterRead="afterRead"
									@delete="deletePic"
								></file-upload>
							</u-form-item>
							<u-form-item labelPosition="top" labelWidth="100%" label="备注">
								<u--textarea
									disableDefaultPadding
									v-model="formData.remark"
									border="none"
									placeholder="备注"
									:placeholderStyle="{ fontSize: '13.5px', color: '#BFC4CC' }"
								></u--textarea>
							</u-form-item>
						</view>
					</u--form>
				</view>
				<view class="footer ios">
					<u-button
						text="提交"
						@click="submitFunc"
						customStyle="width: 702rpx;height: 88rpx;background: #3B75FF;border-radius: 16rpx;font-weight: 500;font-size: 28rpx;color: #FFFFFF;margin:20rpx 24rpx;"
					></u-button>
				</view>
			</z-paging>
		</pageTxt>
	</view>
</template>

<script>
export default {
	data() {
		return {
			loading: false,
			tjkcxxRuleForm: {
				remark: '',
				survey_data: []
			}
		};
	},
	onLoad(option) {
		this.tjkcxxRuleForm.project_id = option.id || '';
	},
	methods: {
		afterRead(files) {
			files.map((item) => {
				let obj = {
					url: item.url
				};
				this.tjkcxxRuleForm.survey_data.push(obj);
			});
		},
		deletePic(e) {
			this.tjkcxxRuleForm.survey_data.splice(e.index, 1);
		},
		async submitFunc() {
			let tjkcxxRuleForm = this.tjkcxxRuleForm;
			let data = {
				remark: tjkcxxRuleForm.remark,
				project_id: tjkcxxRuleForm.project_id
			};
			if (!tjkcxxRuleForm.survey_data.length) {
				uni.showToast({
					title: '请选择资料文件',
					icon: 'error'
				});
				return;
			}
			uni.showLoading({
				title: '文件上传中',
				mask: true
			});
			let survey_data = await this.$upload(tjkcxxRuleForm.survey_data);
			uni.hideLoading();
			console.log(survey_data);
			data.survey_data = survey_data.arrResult;
			this.uploadSurveyData(data);
		},
		// 提交勘场资料
		uploadSurveyData(data) {
			uni.showLoading({
				title: '信息提交中',
				mask: true
			});
			this.$Apipc.uploadSurveyData(data).then((res) => {
				console.log(res, '提交勘场资料');
				uni.hideLoading();
				if (res.code == 200) {
					setTimeout(() => {
						var currentPages = getCurrentPages()[getCurrentPages().length - 2];
						if (currentPages) {
							uni.navigateBack({
								delta: 1
							});
						} else {
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					}, 500);
				}
				uni.showToast({
					title: res.code == 200 ? '操作成功' : res.message,
					icon: res.code == 200 ? 'success' : 'error'
				});
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
